package com.example.exchangeapp.yy.utils;

import static androidx.core.app.ActivityCompat.startActivityForResult;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.example.exchangeapp.MainActivity;
import com.example.exchangeapp.R;
import com.example.exchangeapp.yy.fragment.SendFragment;
import com.example.exchangeapp.yy.request.HttpRequestUtils;

import java.util.HashMap;
import java.util.Map;

// 自定义dialog对话框
public class AlertDialogUtils  {
    private static View view_custom;
    public static AlertDialog.Builder builder;
    public  static AlertDialog alert ;
    public static TextView tv_dialog_title, tv_dialog_content;
    public static Button dialog_cancelBtn,dialog_confirmBtn;
    public static Map<String,Integer> name_id_map =new HashMap<>();
    public static AlertDialogUtils getInstance() {
        return new AlertDialogUtils();
    }
   public static String[] ss=new String[]{
           "北京",
           "上海",
           "深圳"
   };
    public static Map<String,Integer> map =new HashMap<>();
    /**
     * todo 带有确认取消按钮的自定义dialog
     * @param context 上下文对象
     * @param title 标题
     * @param content 内容
     */
    public static void showConfirmDialog(Context context, String title, String content,Activity activity){
        builder = new AlertDialog.Builder(context);
        alert = builder.create();
        alert.show();
         
         //引入布局
        view_custom = LayoutInflater.from(context).inflate(R.layout.activity_dialog_add_goods,null,false);
        tv_dialog_title = view_custom.findViewById(R.id.title);
        tv_dialog_title.setText(title);
//        tv_dialog_content =  view_custom.findViewById(R.id.content);
//        tv_dialog_content.setText(content);

        alert.setCancelable(false); //点击空白处不关闭弹窗

         //为取消按钮设置点击监听
        view_custom.findViewById(R.id.cancel_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
             if(mOnDialogButtonClickListener !=null){
                 mOnDialogButtonClickListener.onNegativeButtonClick(alert);
             }
            }
        });
        //为确认按钮设置点击监听
        view_custom.findViewById(R.id.comfirm_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mOnDialogButtonClickListener !=null){
                    mOnDialogButtonClickListener.onPositiveButtonClick(alert);
                }
            }
        });
        //使用布局
        alert.getWindow().setContentView(view_custom);

         ss = map.keySet().toArray(new String[0]);


    }






    //todo 按钮点击回调接口
    public static OnDialogButtonClickListener mOnDialogButtonClickListener;
    
    public void setMonDialogButtonClickListener(OnDialogButtonClickListener listener){
        this.mOnDialogButtonClickListener = listener;
    }
    public interface OnDialogButtonClickListener{
        void onPositiveButtonClick(AlertDialog dialog); //确认
        void onNegativeButtonClick(AlertDialog dialog); //取消
    }

}

